import {createSlice, createAsyncThunk} from "@reduxjs/toolkit";
import axios from "axios";

const fetchHomeDataAction = createAsyncThunk(
    'fetch/homeData',
    async () => {
        const res = await axios.get("http://123.207.32.32:8000/home/multidata");
        console.log(res.data);
        return res.data.data
    }
)

const homeSlice = createSlice({
    name: 'home',
    initialState: {
        banners: [],
        recommends: []
    },
    reducers: {
        setBanners(state, action) {
            state.banners = action.payload;
        },
        setRecommends(state, action) {
            state.recommends = action.payload;
        }
    },
    extraReducers: (builder) => {
        console.log('builder', builder.addCase);
        builder.addCase(fetchHomeDataAction.fulfilled, (state, action) => {
            console.log(fetchHomeDataAction.fulfilled, action.payload);
        })
    },
})

export default homeSlice.reducer;